/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isSymmetric = function(root) {
  // 中序遍历+回文串判断
  let result = [];
  let stack = [];
  let node = root;
  while(stack.length || node) {
    if(node) {
      stack.push(node);
      node = node.left;
    } else {
      // 开始出栈
      node = stack.pop();
      result.push(node.val || '-');
      node = node.right;
    }
  }
  let i = 0;
  let j = result.length - 1;
  let match = true;
  while(i !== j) {
    let A = result[i];
    let B = result[j];
    if(A === B) {
      i++;
      j--;
    } else {
      match = false;
      break;
    }
  }
  console.log(result, i, j, match)
};

var tree = {
  val: 1,
  left: {
    val: 2,
    // left: {
    //   val: 3
    // },
    right: {
      val: 3
    }
  },
  right: {
    val: 2,
    // left: {
    //   val: 4
    // },
    right: {
      val: 3
    }
  }
}
isSymmetric(tree);